package com.yunji.web.base;

import com.yunji.base.business.MultiUserBusiness;
import com.yunji.base.dto.UserDTO;
import com.yunji.base.vo.UserInfoVO;
import com.yunji.common.annotation.Log;
import com.yunji.common.base.BaseController;
import com.yunji.common.base.response.Response;
import com.yunji.common.base.response.ResponseHelper;
import com.yunji.common.enums.common.BusinessType;
import com.yunji.common.model.domain.SysUserDO;
import com.yunji.common.utils.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @version 1.0
 * @Project: yunji-coffee
 * @Package com.yunji.web.user
 * @FileName MultiUserController.java
 * @Copyright Copyright © 2024 云集互联. All Rights Reserved
 * Company		com
 * @CreateTime 2024-08-17 15:29:30
 * @Description 多用户处理
 * @Modification Author                    History Time			Version				Description
 * --------------------------------------------------------------------------------
 * HuaAo0803@163.com	2024-08-17 15:29:30		1.0					1.0 Version
 * @since JDK 1.8.0_202
 */
@RestController
@Api(tags = "管理端-多用户管理")
@RequestMapping("/container/user")
public class MultiUserController extends BaseController {
    @Resource
    MultiUserBusiness business;

    @GetMapping("/list")
    @ApiOperation("查询用户信息列表")
    public Response<List<SysUserDO>> list(SysUserDO user) {
        List<SysUserDO> list = business.search(user);
        return ResponseHelper.successWithPage(list);
    }

    @PostMapping("/export")
    @ApiOperation("导出用户信息列表")
    @Log(title = "用户信息", businessType = BusinessType.EXPORT)
    public void export(SysUserDO user) {
        List<SysUserDO> list = business.search(user);
        ExcelUtil<SysUserDO> util = new ExcelUtil<>(SysUserDO.class);
        util.exportExcel(response, list, "用户信息数据");
    }

    @GetMapping(value = "/{id}")
    @ApiOperation("获取用户信息详细")
    public Response<UserInfoVO> select(@PathVariable("id") Long id) {
        return ResponseHelper.success(business.select(id));
    }

    @PostMapping
    @ApiOperation("创建用户信息")
    @Log(title = "用户信息", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('system:subUser:add')")
    public Response<Long> create(@RequestBody UserDTO user) {
        return ResponseHelper.success(business.create(user));
    }

    @PutMapping
    @ApiOperation("修改用户信息")
    @PreAuthorize("@ss.hasPermi('system:subUser:edit')")
    @Log(title = "用户信息", businessType = BusinessType.UPDATE)
    public Response<String> update(@RequestBody UserDTO user) {
        business.update(user);
        return ResponseHelper.success("编辑成功");
    }

    @DeleteMapping("/{ids}")
    @ApiOperation("删除用户信息")
    @PreAuthorize("@ss.hasPermi('system:subUser:remove')")
    @Log(title = "用户信息", businessType = BusinessType.DELETE)
    public Response<String> remove(@PathVariable Long... ids) {
        business.delete(ids);
        return ResponseHelper.success("删除成功");
    }
}